package com.usian.jyzx.product.controller;

import com.usian.jyzx.model.entity.product.Brand;
import com.usian.jyzx.model.vo.common.Result;
import com.usian.jyzx.model.vo.common.ResultCodeEnum;
import com.usian.jyzx.product.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 07 05 14 02
 **/

@RestController
@RequestMapping("/api/product/brand")

public class BrandController {

    @Autowired
    BrandService brandService;


    @RequestMapping("/findAll")
    public Result findALl(){
        List<Brand> brandList = brandService.findAll();
        return Result.build(brandList, ResultCodeEnum.SUCCESS);
    }


    @RequestMapping("/findById")
    @Cacheable(value = "brandCache" , key = "#id")
    public Result findById(Long id){
        Brand brand = brandService.findById(id);
        return Result.build(brand, ResultCodeEnum.SUCCESS);
    }
}
